home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / gkismet / PrefsDialog.pm < prev    next >
Text File  |  2005-10-20  |  14KB  |  324 lines

  1. #!/usr/bin/perl -w
  2. #
  3. # $Id: PrefsDialog.pm,v 1.22 2004/03/25 05:24:40 solovam Exp $
  4. #
  5. # This file is a part of gkismet
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20. #
  21.  
  22. #
  23. # PrefsDialog class
  24. #
  25. package PrefsDialog;
  26.  
  27. use Gnome;
  28. use strict;
  29. use Misc;
  30.  
  31. #
  32. # Constructor
  33. #
  34. sub new
  35. {
  36.     my $type = shift;
  37.     my $self = {};
  38.     bless $self, $type;
  39.  
  40.     my $gKismetApplication = shift;
  41.     $self->{'gKismetApplication'} = $gKismetApplication;
  42.     my $preferences = $gKismetApplication->{'preferences'};
  43.  
  44.     my $propertyBox = new Gnome::PropertyBox();
  45.     $self->{'propertyBox'} = $propertyBox;
  46.     $propertyBox->signal_connect('destroy', sub{$self->destroyHandler(@_)});
  47.     $propertyBox->signal_connect('apply', sub {$self->applyHandler(@_)});
  48.     $propertyBox->set_parent($gKismetApplication->getWidget());
  49.  
  50.     # Page 0
  51.     my $nNetworkFields = scalar $preferences->getPref('networkFieldNames');
  52.     my $networkFrame = new Gtk::Frame('Network');
  53.     my $networkTable = new Gtk::Table($nNetworkFields + 1, 2, $false);
  54.     $networkFrame->add($networkTable);
  55.     my $i = 0;
  56.     for my $f ($preferences->getPref('networkFieldNames'))
  57.     {
  58.         my $button = new Gtk::CheckButton($f);
  59.         $button->set_active($preferences->getPref('networkFieldStatus', $f));
  60.         $self->{'networkFieldButton'}{$f} = $button;
  61.         $button->signal_connect('clicked', sub {$self->changedHandler()});
  62.         if(!($i % 2))
  63.         {
  64.             $networkTable->attach($button, 0, 1, $i, $i + 1, 'fill', 'fill', 0, 0);
  65.         }
  66.         else
  67.         {
  68.             $networkTable->attach($button, 1, 2, $i - 1, $i, 'fill', 'fill', 0, 0);
  69.         }
  70.         $i++;
  71.     }
  72.     my $nClientFields = scalar $preferences->getPref('clientFieldNames');
  73.     my $clientFrame = new Gtk::Frame('Client');
  74.     my $clientTable = new Gtk::Table($nClientFields + 1, 2, $false);
  75.     $clientFrame->add($clientTable);
  76.     $i = 0;
  77.     for my $f ($preferences->getPref('clientFieldNames'))
  78.     {
  79.         my $button = new Gtk::CheckButton($f);
  80.         $button->set_active($preferences->getPref('clientFieldStatus', $f));
  81.         $self->{'clientFieldButton'}{$f} = $button;
  82.         $button->signal_connect('clicked', sub {$self->changedHandler()});
  83.         if(!($i % 2))
  84.         {
  85.             $clientTable->attach($button, 0, 1, $i, $i + 1, 'fill', 'fill', 0, 0);
  86.         }
  87.         else
  88.         {
  89.             $clientTable->attach($button, 1, 2, $i - 1, $i, 'fill', 'fill', 0, 0);
  90.         }
  91.         $i++;
  92.     }
  93.     my $hbox = new Gtk::HBox($true, 0);
  94.     $hbox->pack_start($networkFrame, $true, $false, 0);
  95.     $hbox->pack_start($clientFrame, $true, $false, 0);
  96.     my $tabLabel0 = new Gtk::Label('Fields');
  97.     $propertyBox->append_page($hbox, $tabLabel0);
  98.  
  99.     # Page 1
  100.     # Window depths
  101.     my $packetAdjustment = new Gtk::Adjustment($preferences->getPref('packetDepth'), 100, 10000, 100, 1000, 0);
  102.     my $packetSpinButton = new Gtk::SpinButton($packetAdjustment, 0, 0);
  103.     $packetSpinButton->set_numeric($true);
  104.     $packetSpinButton->signal_connect('changed', sub {$self->changedHandler(@_)});
  105.     $self->{'packetSpinButton'} = $packetSpinButton;
  106.     my $stringAdjustment = new Gtk::Adjustment($preferences->getPref('stringDepth'), 100, 10000, 100, 1000, 0);
  107.     my $stringSpinButton = new Gtk::SpinButton($stringAdjustment, 0, 0);
  108.     $stringSpinButton->set_numeric($true);
  109.     $stringSpinButton->signal_connect('changed', sub {$self->changedHandler(@_)});
  110.     $self->{'stringSpinButton'} = $stringSpinButton;
  111.     my $packetLabel = new Gtk::Label('Packet window depth:');
  112.     my $stringLabel = new Gtk::Label('String window depth:');
  113.     my $packetHBox = new Gtk::HBox($true, 0);
  114.     my $stringHBox= new Gtk::HBox($true, 0);
  115.     $packetHBox->pack_start($packetLabel, $true, $true, 20);
  116.     $packetHBox->pack_start($packetSpinButton, $true, $true, 20);
  117.     $stringHBox->pack_start($stringLabel, $true, $true, 20);
  118.     $stringHBox->pack_start($stringSpinButton, $true, $true, 20);
  119.     my $vbox = new Gtk::VBox($false, 0);
  120.     $vbox->pack_start($packetHBox, $false, $false, 20);
  121.     $vbox->pack_start($stringHBox, $false, $false, 20);
  122.     # Units
  123.     my $imperialButton = new Gtk::RadioButton('Imperial units');
  124.     $self->{'imperialButton'} = $imperialButton;
  125.     my $metricButton = new Gtk::RadioButton('Metric units', $imperialButton);
  126.     $self->{'metricButton'} = $metricButton;
  127.     $preferences->getPref('units') eq 'imperial' ? $imperialButton->set_active($true) : $metricButton->set_active($true);
  128.     $imperialButton->signal_connect('clicked', sub {$self->changedHandler()});
  129.     $metricButton->signal_connect('clicked', sub {$self->changedHandler()});
  130.     my $unitVBox = new Gtk::VBox($true, 0);
  131.     $unitVBox->pack_start($imperialButton, $false, $false, 0);
  132.     $unitVBox->pack_start($metricButton, $false, $false, 0);
  133.     my $unitHBox = new Gtk::HBox($false, 0);
  134.     $unitHBox->pack_start($unitVBox, $false, $false, 20);
  135.     $vbox->pack_start($unitHBox, $false, $false, 20);
  136.     # Keep sorted
  137.     my $keepSortedButton = new Gtk::CheckButton('Keep network tree sorted at all times (slow)');
  138.     $keepSortedButton->set_active($preferences->getPref('keepSorted'));
  139.     $self->{'keepSortedButton'} = $keepSortedButton;
  140.     $keepSortedButton->signal_connect('toggled', sub {$self->changedHandler()});
  141.     my $ksHbox = new Gtk::HBox($false, 0);
  142.     $ksHbox->pack_start($keepSortedButton, $false, $false, 20);
  143.     $vbox->pack_start($ksHbox, $false, $false, 20);
  144.     # Assemble
  145.     my $miscFrame = new Gtk::Frame('Misc');
  146.     $miscFrame->add($vbox);
  147.     my $tabLabel1 = new Gtk::Label('Misc');
  148.     $propertyBox->append_page($miscFrame, $tabLabel1);
  149.  
  150.     # Page 2
  151.     # Play binary
  152.     my $playBinaryHBox = new Gtk::HBox($true, 0);
  153.     my $playBinaryEntry = new Gtk::Entry();
  154.     $self->{'playBinaryEntry'} = $playBinaryEntry;
  155.     $playBinaryEntry->set_text($preferences->getPref('playBinary'));
  156.     $playBinaryEntry->signal_connect('changed', sub{$self->changedHandler()});
  157.     my $playBinaryLabel = new Gtk::Label('Sound play binary');
  158.     $playBinaryHBox->pack_start($playBinaryLabel, $true, $true, 20);
  159.     $playBinaryHBox->pack_end($playBinaryEntry, $true, $true, 20);
  160.  
  161.     # Network sound
  162.     my $networkSoundHBox = new Gtk::HBox($true, 0);
  163.     my $networkSoundEntry = new Gtk::Entry();
  164.     $self->{'networkSoundEntry'} = $networkSoundEntry;
  165.     $networkSoundEntry->set_text($preferences->getPref('newNetworkSound'));
  166.     $networkSoundEntry->signal_connect('changed', sub{$self->changedHandler()});
  167.     my $networkSoundButton = new Gtk::CheckButton('New network sound');
  168.     $networkSoundButton->set_active($preferences->getPref('networkSoundEnabled'));
  169.     $self->{'networkSoundEnabledButton'} = $networkSoundButton;
  170.     $networkSoundButton->signal_connect('toggled', sub {$networkSoundEntry->set_sensitive($networkSoundButton->active()); $self->changedHandler()});
  171.     $networkSoundEntry->set_sensitive($networkSoundButton->active());
  172.     $networkSoundHBox->pack_start($networkSoundButton, $true, $true, 20);
  173.     $networkSoundHBox->pack_end($networkSoundEntry, $true, $true, 20);
  174.  
  175.     # Alert sound
  176.     my $alertSoundHBox = new Gtk::HBox($true, 0);
  177.     my $alertSoundEntry = new Gtk::Entry();
  178.     $self->{'alertSoundEntry'} = $alertSoundEntry;
  179.     $alertSoundEntry->set_text($preferences->getPref('alertSound'));
  180.     $alertSoundEntry->signal_connect('changed', sub{$self->changedHandler()});
  181.     my $alertSoundButton = new Gtk::CheckButton('Alert sound');
  182.     $alertSoundButton->set_active($preferences->getPref('alertSoundEnabled'));
  183.     $self->{'alertSoundEnabledButton'} = $alertSoundButton;
  184.     $alertSoundButton->signal_connect('toggled', sub {$alertSoundEntry->set_sensitive($alertSoundButton->active()); $self->changedHandler()});
  185.     $alertSoundEntry->set_sensitive($alertSoundButton->active());
  186.     $alertSoundHBox->pack_start($alertSoundButton, $true, $true, 20);
  187.     $alertSoundHBox->pack_end($alertSoundEntry, $true, $true, 20);
  188.  
  189.     # GPS sound
  190.     my $gpsAcqSoundEntry = new Gtk::Entry();
  191.     $self->{'gpsAcqSoundEntry'} = $gpsAcqSoundEntry;
  192.     $gpsAcqSoundEntry->set_text($preferences->getPref('gpsAcqSound'));
  193.     $gpsAcqSoundEntry->signal_connect('changed', sub{$self->changedHandler()});
  194.     my $gpsLostSoundEntry = new Gtk::Entry();
  195.     $self->{'gpsLostSoundEntry'} = $gpsLostSoundEntry;
  196.     $gpsLostSoundEntry->set_text($preferences->getPref('gpsLostSound'));
  197.     $gpsLostSoundEntry->signal_connect('changed', sub{$self->changedHandler()});
  198.     my $gpsEntryVBox = new Gtk::VBox($true, 0);
  199.     $gpsEntryVBox->pack_start($gpsAcqSoundEntry, $false, $false, 0);
  200.     $gpsEntryVBox->pack_start($gpsLostSoundEntry, $false, $false, 0);
  201.     my $gpsSoundButton = new Gtk::CheckButton('GPS acquired/lost sound');
  202.     $gpsSoundButton->set_active($preferences->getPref('gpsSoundEnabled'));
  203.     $self->{'gpsSoundEnabledButton'} = $gpsSoundButton;
  204.     $gpsSoundButton->signal_connect('toggled', sub {$gpsAcqSoundEntry->set_sensitive($gpsSoundButton->active());
  205.         $gpsLostSoundEntry->set_sensitive($gpsSoundButton->active()); $self->changedHandler()});
  206.     $gpsAcqSoundEntry->set_sensitive($gpsSoundButton->active());
  207.     $gpsLostSoundEntry->set_sensitive($gpsSoundButton->active());
  208.     my $gpsSoundHBox = new Gtk::HBox($true, 0);
  209.     $gpsSoundHBox->pack_start($gpsSoundButton, $true, $true, 20);
  210.     $gpsSoundHBox->pack_end($gpsEntryVBox, $true, $true, 20);
  211.  
  212.     # Traffic
  213.     my $trafficSoundEntry = new Gtk::Entry();
  214.     $self->{'trafficSoundEntry'} = $trafficSoundEntry;
  215.     $trafficSoundEntry->set_text($preferences->getPref('trafficSound'));
  216.     $trafficSoundEntry->signal_connect('changed', sub{$self->changedHandler()});
  217.     my $junkTrafficSoundEntry = new Gtk::Entry();
  218.     $self->{'junkTrafficSoundEntry'} = $junkTrafficSoundEntry;
  219.     $junkTrafficSoundEntry->set_text($preferences->getPref('junkTrafficSound'));
  220.     $junkTrafficSoundEntry->signal_connect('changed', sub{$self->changedHandler()});
  221.     my $trafficEntryVBox = new Gtk::VBox($true, 0);
  222.     $trafficEntryVBox->pack_start($trafficSoundEntry, $false, $false, 0);
  223.     $trafficEntryVBox->pack_start($junkTrafficSoundEntry, $false, $false, 0);
  224.     my $trafficSoundButton = new Gtk::CheckButton('Traffic/Junk traffic sound');
  225.     $trafficSoundButton->set_active($preferences->getPref('trafficSoundEnabled'));
  226.     $self->{'trafficSoundEnabledButton'} = $trafficSoundButton;
  227.     $trafficSoundButton->signal_connect('toggled', sub {$trafficSoundEntry->set_sensitive($trafficSoundButton->active());
  228.         $junkTrafficSoundEntry->set_sensitive($trafficSoundButton->active()); $self->changedHandler()});
  229.     $trafficSoundEntry->set_sensitive($trafficSoundButton->active());
  230.     $junkTrafficSoundEntry->set_sensitive($trafficSoundButton->active());
  231.     my $trafficSoundHBox = new Gtk::HBox($true, 0);
  232.     $trafficSoundHBox->pack_start($trafficSoundButton, $true, $true, 20);
  233.     $trafficSoundHBox->pack_end($trafficEntryVBox, $true, $true, 20);
  234.  
  235.     # Pack all
  236.     my $soundVBox = new Gtk::VBox($true, 0);
  237.     $soundVBox->pack_start($playBinaryHBox, $false, $false, 0);
  238.     $soundVBox->pack_start($networkSoundHBox, $false, $false, 0);
  239.     $soundVBox->pack_start($alertSoundHBox, $false, $false, 0);
  240.     $soundVBox->pack_start($gpsSoundHBox, $false, $false, 0);
  241.     $soundVBox->pack_start($trafficSoundHBox, $false, $false, 0);
  242.     my $soundFrame = new Gtk::Frame('Sound');
  243.     $soundFrame->add($soundVBox);
  244.     my $tabLabel2 = new Gtk::Label('Sound');
  245.     $propertyBox->append_page($soundFrame, $tabLabel2);
  246.  
  247.     # Show widget
  248.     $propertyBox->show_all();
  249.  
  250.     return $self;
  251. }
  252.  
  253. #
  254. # Destroy handler
  255. #
  256. sub destroyHandler
  257. {
  258.     my $self = shift;
  259.     $self->{'gKismetApplication'}->dialogClose('PrefsDialog');
  260. }
  261.  
  262. #
  263. # Handle a change to a widget
  264. #
  265. sub changedHandler
  266. {
  267.     my $self = shift;
  268.     $self->{'propertyBox'}->changed();
  269.     return($false);
  270. }
  271.  
  272. #
  273. # Applied handler
  274. #
  275. sub applyHandler
  276. {
  277.     my $self = shift;
  278.     my $widget = shift;
  279.     my $page = shift;
  280.  
  281.     if($page != -1)
  282.     {
  283.         return($false);
  284.     }
  285.  
  286.     my $preferences = $self->{'gKismetApplication'}->{'preferences'};
  287.     for my $f ($preferences->getPref('networkFieldNames'))
  288.     {
  289.         $preferences->setPref('networkFieldStatus', $f, $self->{'networkFieldButton'}{$f}->get_active());
  290.     }
  291.     for my $f ($preferences->getPref('clientFieldNames'))
  292.     {
  293.         $preferences->setPref('clientFieldStatus', $f, $self->{'clientFieldButton'}{$f}->get_active());
  294.     }
  295.     $preferences->setPref('packetDepth', $self->{'packetSpinButton'}->get_value_as_int());
  296.     $preferences->setPref('stringDepth', $self->{'stringSpinButton'}->get_value_as_int());
  297.     $preferences->setPref('units', $self->{'imperialButton'}->get_active() ? 'imperial' : 'metric');
  298.     $preferences->setPref('keepSorted', $self->{'keepSortedButton'}->get_active() ? $true : $false);
  299.     $preferences->setPref('playBinary', $self->{'playBinaryEntry'}->get_text());
  300.     $preferences->setPref('networkSoundEnabled', $self->{'networkSoundEnabledButton'}->get_active());
  301.     $preferences->setPref('newNetworkSound', $self->{'networkSoundEntry'}->get_text());
  302.     $preferences->setPref('alertSoundEnabled', $self->{'alertSoundEnabledButton'}->get_active());
  303.     $preferences->setPref('alertSound', $self->{'alertSoundEntry'}->get_text());
  304.     $preferences->setPref('gpsSoundEnabled', $self->{'gpsSoundEnabledButton'}->get_active());
  305.     $preferences->setPref('gpsAcqSound', $self->{'gpsAcqSoundEntry'}->get_text());
  306.     $preferences->setPref('gpsLostSound', $self->{'gpsLostSoundEntry'}->get_text());
  307.     $preferences->setPref('trafficSoundEnabled', $self->{'trafficSoundEnabledButton'}->get_active());
  308.     $preferences->setPref('trafficSound', $self->{'trafficSoundEntry'}->get_text());
  309.     $preferences->setPref('junkTrafficSound', $self->{'junkTrafficSoundEntry'}->get_text());
  310.     $preferences->save();
  311.     return($false);
  312. }
  313.  
  314. #
  315. # Get widget
  316. #
  317. sub getWidget
  318. {
  319.     my $self = shift;
  320.     return $self->{'propertyBox'};
  321. }
  322.  
  323. 1;
  324.